<template>
  <div class="app-container">

    <el-table v-loading="loading" :data="personnelMattersList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="考核编号" align="center" prop="personAssessmentId"/>
      <el-table-column label="考核年份" align="center" prop="assessmentTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.assessmentTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户姓名" align="center" prop="nickName"/>
      <el-table-column label="身份证号" align="center" prop="userIdcardnum"/>
      <el-table-column label="考核结果" align="center" prop="assessmentResult">
        <template slot-scope="{row}">
          <el-tag
            type="info"
            v-show="row.assessmentResult==='0'"
          >
            未考核
          </el-tag>
          <el-tag
            type="success"
            v-show="row.assessmentResult==='1'"
          >
            优秀
          </el-tag>
          <el-tag
            type="success"
            v-show="row.assessmentResult==='2'"
          >
            合格
          </el-tag>
          <el-tag
            type="success"
            v-show="row.assessmentResult==='3'"
          >
            基本合格
          </el-tag>
          <el-tag
            type="danger"
            v-show="row.assessmentResult==='4'"
          >
            不合格
          </el-tag>
          <el-tag
            type="danger"
            v-show="row.assessmentResult==='5'"
          >
            不定等次
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="描述" align="center" prop="assessmentResultInfo"/>


      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleView(scope.row)"
            v-hasPermi="['personnelMatters:ordinaryStaff:query']"
          >查看
          </el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或审核人事考核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>

      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="用户姓名" prop="nickName">
          <el-input v-model="form.nickName" :disabled="form.personAssessmentId != undefined"/>
        </el-form-item>
        <el-form-item label="身份证号" prop="userIdcardnum">
          <el-input v-model="form.userIdcardnum" :disabled="form.personAssessmentId != undefined"/>
        </el-form-item>
        <el-form-item label="考核结果" prop="assessmentResult">
          <el-input v-model="form.assessmentResult"/>
        </el-form-item>
        <el-form-item label="考核评语" prop="assessmentComment">
          <el-input v-model="form.assessmentComment" placeholder="未输入考核评语" type="textarea"/>
        </el-form-item>
        <el-form-item label="考核年份" prop="assessmentTime">
          <el-date-picker clearable
                          v-model="form.assessmentTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择考核年份"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="personRemarks">
          <el-input v-model="form.personRemarks"  placeholder="未输入备注" type="textarea"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="open=false">确 定</el-button>
        <el-button @click="open=false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  ordinaryStaffGetInfo,
  ordinaryStaffList
} from '@/api/personnelMatters/personnelMatters'

export default {
  name: 'OrdinaryStaff',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 人事考核表格数据
      personnelMattersList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nickName: null,
        assessmentResult: null
      },
      // 表单参数
      form: {}
      // 表单校验
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询人事考核列表 */
    getList() {
      this.loading = true
      ordinaryStaffList(this.queryParams).then(response => {
        this.personnelMattersList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        personAssessmentId: null,
        userId: null,
        nickName: null,
        userIdcardnum: null,
        assessmentResult: null,
        assessmentComment: null,
        assessmentTime: null,
        personRemarks: null
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.personAssessmentId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    handleView(row) {
      this.reset()
      const personAssessmentId = row.personAssessmentId || this.ids
      ordinaryStaffGetInfo(personAssessmentId).then(response => {
        this.form = response.data
        this.open = true
        this.title = '查看人事考核'
      })
    }

  }
}
</script>
